package edu.hrbu.spring.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.hrbu.spring.mapper.DeptMapper;
import edu.hrbu.spring.pojo.Dept;
import edu.hrbu.spring.service.DeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐登宇
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Resource(name = "deptMapper")
    DeptMapper deptMapper;

    @Override
    public List<Dept> getAllDeptPage(int page, int size) {
        PageHelper.startPage(page, size);
        List<Dept> deptList = deptMapper.getDeptList();
        PageInfo<Dept> deptPageInfo = new PageInfo<>(deptList);
//        System.out.println(deptPageInfo.getList());
        return deptPageInfo.getList();
    }

    @Override
    public Dept getInfo(int deptId) {
        return deptMapper.getInfo(deptId);
    }

    @Override
    public List<Dept> getAllDept() {
        return deptMapper.getDeptList();
    }

    @Override
    public boolean save(Dept dept) {
        return deptMapper.insert(dept) == 1;
    }

    @Override
    public boolean remove(Integer deptId) {
        return deptMapper.delete(deptId) == 1;
    }

    @Override
    public boolean edit(Dept dept) {
        return deptMapper.update(dept) == 1;
    }
}
